//
//  MytableHraderView.m
//  Golf
//
//  Created by chengxu on 15/12/21.
//  Copyright © 2015年 Shenzhen Tentinet Technology Co,. Ltd. All rights reserved.
//

#import "MytableHraderView.h"
#import "MY_infoModel.h"
#import "attentionView.h"

#define Rgb(a,b,c) [UIColor colorWithRed:a/255.0f green:b/255.0f blue:c/255.0f alpha:1]

@implementation MytableHraderView

- (id)initWithFrame:(CGRect)frame model:(MY_infoModel *)model{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kClearCOLOR;
        
        [self initView:model];
    }
    return self;
}


//视图加载
- (void)initView:(MY_infoModel *)model{
//    //背景view
    UIView *img = [[UIView alloc]initWithFrame:krect(0, 0, self.golf_width, self.golf_height)];
//    img.backgroundColor = kOrangeCOLOR;
    [self addSubview:img];
    //头像 kScreenWidth/2 - 36-15
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(self.golf_width/2 - 36, 5, 72, 72)];
    [imageView sd_setImageWithURL:[NSURL URLWithString:@"头像url"] placeholderImage:[UIImage imageNamed:@"001.jpg"]];
    [imageView.layer setMasksToBounds:YES];
    [imageView.layer setCornerRadius:36];
    [imageView.layer setBorderWidth:3];
    [imageView.layer setBorderColor:[[HexRGB(0xFFFFFF) colorWithAlphaComponent:0.25] CGColor]];
    
    UIImageView *levImage = [[UIImageView alloc]initWithFrame:krect(imageView.golf_right-18, 5, 20, 20)];
    levImage.backgroundColor = kNaviBarCOLOR;
    [levImage setImage:kCreatImage(@"001.jpg")];
    levImage.layer.cornerRadius = 5;
    levImage.clipsToBounds = YES;
    [self addSubview:imageView];
    [self addSubview:levImage];


    
    UIButton *imgBtn = [[UIButton alloc]initWithFrame:krect(self.golf_width/2 - 36, 5, 72, 72)];
    imgBtn.tag = 1004;
    [imgBtn.layer setMasksToBounds:YES];
    [imgBtn.layer setCornerRadius:36];
    [imgBtn.layer setBorderWidth:3];
    [imgBtn.layer setBorderColor:[[HexRGB(0xFFFFFF) colorWithAlphaComponent:0.25] CGColor]];
    
    [self addSubview:imgBtn];
    
    //瑜秀号:
    _yuxiuNum = [[UILabel alloc]initWithFrame:krect(0, imgBtn.golf_bottom +5, kScreenWidth-60, 20)];
    _yuxiuNum.text = @"瑜秀号:58241116";
    _yuxiuNum.textAlignment = NSTextAlignmentCenter;
    _yuxiuNum.textColor = [UIColor whiteColor];
    _yuxiuNum.font = [UIFont systemFontOfSize:12];
    
    
    NSString *nameStr = @"zhaosongshu";
    UIFont *font = Font(13);
    CGSize size = CGSizeMake(999, 20);
    float NameLwidth = [nameStr boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : font} context:nil].size.width;
    //昵称
    _namelbl = [[UILabel alloc]initWithFrame:krect(self.golf_width/2-20-NameLwidth/2 , _yuxiuNum.golf_bottom+5, NameLwidth, 20)];
    _namelbl.text = nameStr;
    _namelbl.textAlignment = NSTextAlignmentCenter;
    _namelbl.textColor = [UIColor whiteColor];
    _namelbl.font = [UIFont systemFontOfSize:13];
    [self addSubview:_namelbl];
    
    [self addSubview:_yuxiuNum];
    
    //性别icon
    UIImageView *sexIcon = [[UIImageView alloc]initWithFrame:krect(_namelbl.golf_right, _namelbl.golf_top, 20, 20)];
    [sexIcon setImage:[UIImage imageNamed:@"header"]];
    [self addSubview:sexIcon];
    
    //等级btn
    UIButton *levButton = [[UIButton alloc]initWithFrame:krect(sexIcon.golf_right, sexIcon.golf_top, 55, 20)];
    [levButton setBackgroundColor:kLightGrayCOLOR];
    [levButton setTitle:@"lev:1" forState:UIControlStateNormal];
    [self addSubview:levButton];
    
    //个性签名
    _signLabel = [[UILabel alloc]initWithFrame:krect(10, _namelbl.golf_bottom, self.golf_width-20, 20)];
    _signLabel.font = Font(12);
    _signLabel.textColor = kWhiteCOLOR;
    NSString *signStr = @"我要这天，再遮不住我眼,要这地，再埋不了我心,我要这众生都明我意,要这满天神佛都烟消云散";
    float wid = [signStr boundingRectWithSize:CGSizeMake(999, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12]} context:nil].size.width;
    if (wid>kScreenWidth-80) {
        //
        _signLabel.numberOfLines = 2;
        [_signLabel setFrame:krect(10, _namelbl.golf_bottom, self.golf_width-20, 40)];
    }

    _signLabel.text = signStr;
    _signLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_signLabel];
    
    
    
    //粉丝按钮
    float aw = kScreenWidth-60;
    
    attentionView *attentionV = [[attentionView alloc]initWithFrame:krect(aw/4 -20, _signLabel.golf_bottom+2, 50, 50)];
    attentionV.numStr = @"2113";
    attentionV.type = @"粉丝";
    attentionV.layer.cornerRadius = 5;
    attentionV.clipsToBounds = YES;
    [self addSubview:attentionV];
    
    //关注按钮
    attentionView *fanView = [[attentionView alloc]initWithFrame:krect(aw-(aw/4 -20) - 50, _signLabel.golf_bottom+2, 50, 50)];
    fanView.numStr = @"1172";
    fanView .type = @"关注";
    fanView.layer.cornerRadius = 5;
    fanView.clipsToBounds = YES;
    [self addSubview:fanView];
  
    NSLog(@"avFrame :%@, fanFrame:%@ ,self.frame:%@",NSStringFromCGRect(attentionV.frame),NSStringFromCGRect(fanView.frame),NSStringFromCGRect(self.frame));
    
    _startButton = [[UIButton alloc]initWithFrame:krect(20, fanView.golf_bottom +12, self.golf_width-40, 30)];
    _startButton.backgroundColor = kColorRGB(255, 222, 173);
    [_startButton setTitle:@"开启直播" forState:UIControlStateNormal];
    [_startButton addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    _startButton.layer.cornerRadius = 15;

    [self addSubview:_startButton];
    
    //2016-06-27 14:51:30.491 YUXiu[6109:1334962] avFrame :{{58.75, 172}, {50, 50}}, fanFrame:{{216.25, 172}, {50, 50}} ,self.frame:{{30, 0}, {315, 278}}
}

-(void)click{
    //这里在判断是直播还是，关注
    if (_block) {
        _block(@"开启直播or关注主播");
    }
    
    
}

@end
